#ifndef TEXTEDIT_H
#define TEXTEDIT_H

#include <QFile>
#include <QWidget>

namespace Ui {
class TextEdit;
}

class TextEdit : public QWidget
{
    Q_OBJECT

public:
    explicit TextEdit(QString absolute_path, int center_x=10, QWidget *parent=nullptr);
    ~TextEdit();

    static const int width_ = 500;
    static const int height_ = 550;

private:
    Ui::TextEdit *ui;
    QFile file;
    bool something_changed;
    QString filename_;
    bool pressed_ctrl;  // 记录ctrl键是否被按下
    int pointer_x;  // 下方箭头中心的x坐标

    void save_file();  // 保存输入的文字到文件
    void set_auto_save();  // 设置自动保存
    void paintEvent(QPaintEvent *);
    void keyPressEvent(QKeyEvent *);
    void keyReleaseEvent(QKeyEvent *);
};

#endif // TEXTEDIT_H
